package test;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created by huangfei on 2018/9/17.
 */
public class PhoenixClient {
//    private static String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
    private static String driver = "org.apache.phoenix.queryserver.client.Driver";

    Connection connection;

    public PhoenixClient() throws SQLException, ClassNotFoundException {
        Class.forName(driver);

        connection = DriverManager.getConnection("jdbc:phoenix:192.168.1.2:2181");
        System.out.println("PhoenixClient success");
    }

    public List<Map<String, Object>> query(String sql) throws SQLException {
        QueryRunner run = new QueryRunner();

        return run.query(connection,sql,new MapListHandler(){});
    }



}
